﻿using System;

namespace SharePhone.Core
{
    public enum CorePopulateRule
    {
        None,
        Sharepoint,
        SharepointReadOnly,
        FromFactory
    }

    public enum FieldImportance
    {
        Required,
        Optional
    }

    [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
    public class CoreIndexAttribute : Attribute
    {
        /// <summary>
        /// Name of the property that returns the ID of the class
        /// </summary>
        public string Property;

        public static CoreIndexAttribute GetIndexAttribute(object o)
        {
            object[] atts = o.GetType().GetCustomAttributes(typeof (CoreIndexAttribute), false);
            if (atts.Length > 0)
                return atts[0] as CoreIndexAttribute;
            return null;
        }
    }

    /// <summary>
    /// Used to annotate properties in core objects for use with reflection.
    /// </summary>
    [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
    public class CoreFieldAttribute : Attribute
    {
        /// <summary>
        /// Determines how this field should be treated
        /// </summary>
        public CorePopulateRule PopulateRule { get; set; }

        /// <summary>
        /// The name of the sharepoint field this field corresponds to
        /// </summary>
        public string FieldName { get; set; }

        public FieldImportance Importance { get; set; }
        public object DefaultValue { get; set; }
    }
}